package com.zhangsan.senior1.week1.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhangsan.senior1.week1.dao.JobDao;
import com.zhangsan.senior1.week1.domain.Job;
import com.zhangsan.senior1.week1.domain.Light;
import com.zhangsan.senior1.week1.domain.Story;
import com.zhangsan.senior1.week1.service.JobSer;

@Service
public class JobSerImp implements JobSer{
	@Autowired
	private JobDao jDao;

	public List<Job> selectall(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return jDao.selectall(map);
	}

	public List<Story> selectstory(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return jDao.selectstory(map);
	}

	public Integer addone(Job job) {
		Integer num = jDao.addone(job);
		Map<String, Object> map=new HashMap<String, Object>();
		String[] split = job.getLnames().split(",");
		for (String s : split) {
			Light light = jDao.selectlight(s);
			if(light!=null){
				map.put("jid", job.getJid());
				map.put("lid", light.getLid());
				jDao.addcon(map);
			}else{
				Light light2=new Light(null, s);
				jDao.addlight(light2);
				map.put("jid", job.getJid());
				map.put("lid", light2.getLid());
				jDao.addcon(map);
			}
		}
		return num;
	}

	public Job byone(Map<String, Object> map) {
		return jDao.byone(map);
	}
}
